Skip to content

Improve types for Pull Request payload#565

Closed
sorenlouv wants to merge 2 commits intoactions:masterfrom
sorenlouv:patch-1
Closed

Improve types for Pull Request payload#565
sorenlouv wants to merge 2 commits intoactions:masterfrom
sorenlouv:patch-1

Conversation

@sorenlouv
Copy link
Copy Markdown

This PR adds types for a few more fields for the pull request payload. I also went ahead and did the types for the full pull request payload but that might be too be a change - I'll leave that up to the maintainers :)

Show full type declaration for Pull Request payload
interface Organization {
  avatar_url: string;
  description?: string;
  events_url: string;
  hooks_url: string;
  id: number;
  issues_url: string;
  login: string;
  members_url: string;
  node_id: string;
  public_members_url: string;
  repos_url: string;
  url: string;
}

interface Href {
    href: string;
  }

interface Links {
  comments: Href;
  commits: Href;
  html: Href;
  issue: Href;
  review_comment: Href;
  review_comments: Href;
  self: Href;
  statuses: Href;
}

interface Owner {
  avatar_url: string;
  events_url: string;
  followers_url: string;
  following_url: string;
  gists_url: string;
  gravatar_id: string;
  html_url: string;
  id: number;
  login: string;
  node_id: string;
  organizations_url: string;
  received_events_url: string;
  repos_url: string;
  site_admin: boolean;
  starred_url: string;
  subscriptions_url: string;
  type: string;
  url: string;
}

interface Repo {
  allow_merge_commit: boolean;
  allow_rebase_merge: boolean;
  allow_squash_merge: boolean;
  archive_url: string;
  archived: boolean;
  assignees_url: string;
  blobs_url: string;
  branches_url: string;
  clone_url: string;
  collaborators_url: string;
  comments_url: string;
  commits_url: string;
  compare_url: string;
  contents_url: string;
  contributors_url: string;
  created_at: Date;
  default_branch: string;
  delete_branch_on_merge: boolean;
  deployments_url: string;
  description: string;
  disabled: boolean;
  downloads_url: string;
  events_url: string;
  fork: boolean;
  forks: number;
  forks_count: number;
  forks_url: string;
  full_name: string;
  git_commits_url: string;
  git_refs_url: string;
  git_tags_url: string;
  git_url: string;
  has_downloads: boolean;
  has_issues: boolean;
  has_pages: boolean;
  has_projects: boolean;
  has_wiki: boolean;
  homepage?: string;
  hooks_url: string;
  html_url: string;
  id: number;
  issue_comment_url: string;
  issue_events_url: string;
  issues_url: string;
  keys_url: string;
  labels_url: string;
  language?: any;
  languages_url: string;
  license?: any;
  merges_url: string;
  milestones_url: string;
  mirror_url?: any;
  name: string;
  node_id: string;
  notifications_url: string;
  open_issues: number;
  open_issues_count: number;
  owner: Owner;
  private: boolean;
  pulls_url: string;
  pushed_at: Date;
  releases_url: string;
  size: number;
  ssh_url: string;
  stargazers_count: number;
  stargazers_url: string;
  statuses_url: string;
  subscribers_url: string;
  subscription_url: string;
  svn_url: string;
  tags_url: string;
  teams_url: string;
  trees_url: string;
  updated_at: Date;
  url: string;
  watchers: number;
  watchers_count: number;
}

interface User {
  avatar_url: string;
  events_url: string;
  followers_url: string;
  following_url: string;
  gists_url: string;
  gravatar_id: string;
  html_url: string;
  id: number;
  login: string;
  node_id: string;
  organizations_url: string;
  received_events_url: string;
  repos_url: string;
  site_admin: boolean;
  starred_url: string;
  subscriptions_url: string;
  type: string;
  url: string;
}

interface Base {
  label: string;
  ref: string;
  repo: Repo;
  sha: string;
  user: User;
}

interface Head {
  label: string;
  ref: string;
  repo: Repo;
  sha: string;
  user: User;
}

interface Label {
  color: string;
  default: boolean;
  description: string;
  id: any;
  name: string;
  node_id: string;
  url: string;
}

interface PullRequest {
  _links: Links;
  active_lock_reason?: any;
  additions: number;
  assignee?: any;
  assignees: any[];
  author_association: string;
  base: Base;
  body: string;
  changed_files: number;
  closed_at: Date;
  comments: number;
  comments_url: string;
  commits: number;
  commits_url: string;
  created_at: Date;
  deletions: number;
  diff_url: string;
  draft: boolean;
  head: Head;
  html_url: string;
  id: number;
  issue_url: string;
  labels: Label[];
  locked: boolean;
  maintainer_can_modify: boolean;
  merge_commit_sha: string;
  mergeable: boolean;
  mergeable_state: string;
  merged: boolean;
  merged_at?: any;
  merged_by?: any;
  milestone?: any;
  node_id: string;
  number: number;
  patch_url: string;
  rebaseable: boolean;
  requested_reviewers: any[];
  requested_teams: any[];
  review_comment_url: string;
  review_comments: number;
  review_comments_url: string;
  state: string;
  statuses_url: string;
  title: string;
  updated_at: Date;
  url: string;
  user: User;
}

interface Repository {
  archive_url: string;
  archived: boolean;
  assignees_url: string;
  blobs_url: string;
  branches_url: string;
  clone_url: string;
  collaborators_url: string;
  comments_url: string;
  commits_url: string;
  compare_url: string;
  contents_url: string;
  contributors_url: string;
  created_at: Date;
  default_branch: string;
  deployments_url: string;
  description: string;
  disabled: boolean;
  downloads_url: string;
  events_url: string;
  fork: boolean;
  forks: number;
  forks_count: number;
  forks_url: string;
  full_name: string;
  git_commits_url: string;
  git_refs_url: string;
  git_tags_url: string;
  git_url: string;
  has_downloads: boolean;
  has_issues: boolean;
  has_pages: boolean;
  has_projects: boolean;
  has_wiki: boolean;
  homepage?: any;
  hooks_url: string;
  html_url: string;
  id: number;
  issue_comment_url: string;
  issue_events_url: string;
  issues_url: string;
  keys_url: string;
  labels_url: string;
  language?: any;
  languages_url: string;
  license?: any;
  merges_url: string;
  milestones_url: string;
  mirror_url?: any;
  name: string;
  node_id: string;
  notifications_url: string;
  open_issues: number;
  open_issues_count: number;
  owner: Owner;
  private: boolean;
  pulls_url: string;
  pushed_at: Date;
  releases_url: string;
  size: number;
  ssh_url: string;
  stargazers_count: number;
  stargazers_url: string;
  statuses_url: string;
  subscribers_url: string;
  subscription_url: string;
  svn_url: string;
  tags_url: string;
  teams_url: string;
  trees_url: string;
  updated_at: Date;
  url: string;
  watchers: number;
  watchers_count: number;
}

interface Sender {
  avatar_url: string;
  events_url: string;
  followers_url: string;
  following_url: string;
  gists_url: string;
  gravatar_id: string;
  html_url: string;
  id: number;
  login: string;
  node_id: string;
  organizations_url: string;
  received_events_url: string;
  repos_url: string;
  site_admin: boolean;
  starred_url: string;
  subscriptions_url: string;
  type: string;
  url: string;
}

interface WebhookPullRequestPayload {
  action: string;
  number: number;
  organization: Organization;
  pull_request: PullRequest;
  repository: Repository;
  sender: Sender;
}

@sorenlouv
Copy link
Copy Markdown
Author

I found a better solution:

import { EventPayloads } from '@octokit/webhooks';
const payload = context.payload as EventPayloads.WebhookPayloadPullRequest;

@sorenlouv sorenlouv closed this Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant